package com.bkhech.spring;

import com.bkhech.spring.domain.LevelViews;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author guowm
 * @date 2023/3/20
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ApiResponse<T> {
    @JsonView(LevelViews.Public.class)
    private int code;
    @JsonView(LevelViews.Public.class)
    private String message;
    @JsonView(LevelViews.Public.class)
    private T data;

    public static <T> ApiResponse<T> success(T data) {
        return ApiResponse.<T>builder().code(200).data(data).build();
    }

    public static <T> ApiResponse<T> fail(String message) {
        return ApiResponse.<T>builder().code(500).message(message).build();
    }

}
